<?php
/**
 * Created by PhpStorm.
 * User: 王松
 * Time: 2017/6/27 18:32
 */

namespace App\Transformers;

use App\Models\MedicalFollowUp;
use App\Models\MedicalHpiSub;
use Illuminate\Http\Request;

class FollowUpTransformer extends PreviousFollowWithRecordTransformer
{

    protected $availableIncludes = ['hpiSub', 'previousSub', 'previousMedication'];

    /**
     * @param \App\Models\MedicalFollowUp $followUp
     * @return array
     */
    public function transform($followUp)
    {
        return [
            'id'                  => $followUp->id,
            'record_id'           => $followUp->record_id,
            'blood_glucose'       => $followUp->blood_glucose,
            'interval_evaluation' => $followUp->interval_evaluation,
            'interval_symptom'    => $followUp->interval_symptom,
            'diet'                => $followUp->diet,
            'sport'               => $followUp->sport,
            'sport_time'          => $followUp->sport_time,
            'sport_strength'      => $followUp->sport_strength,
            'normal'              => $followUp->normal,
            'thyroid'             => $followUp->thyroid,
            'adrenal_gland'       => $followUp->adrenal_gland,
            'remark'              => $followUp->remark,
        ];
    }

    /**
     * 获取随诊的现病史组
     * @param \App\Models\MedicalFollowUp $followUp
     * @return \League\Fractal\Resource\Collection
     */
    public function includeHpiSub(MedicalFollowUp $followUp)
    {
        return $this->collection(
            MedicalHpiSub::where(['record_id' => $followUp->record_id])->get(),
            new HpiSubTransformer()
        );
    }
}